<template>
    <div class="big_box" :model="from">
        <!-- <el-row :gutter="20">
            <el-col :span="8" :offset="2">
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>汽车保养</span>
                    </div>
                    <div>
                        <el-form label-width="120px">
                            <el-form-item label="发起人" prop="SponsorUser">
                                <el-select width="100%" v-model="from.contractUserPhone" multiple filterable
                                    placeholder="请选择发起人" style="width:100%">
                                    <el-option value="">发起人</el-option>
                                    <el-option v-for="(v, k) in AllUsers" :value="v.Phone" :data-userid="v.Phone"
                                        :label="v.UserName" v-text="v.UserName" />
                                </el-select>
                            </el-form-item>
                            <el-form-item label="保养间隔里程数" prop="SponsorUser" v-model="from.maintain">
                                <el-input type="text" v-model="from.contract"></el-input>
                            </el-form-item>
                        </el-form>

                    </div>
                </el-card>
            </el-col>

            <el-col :span="8" :offset="2">
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>合同到期</span>
                    </div>
                    <div>
                        <el-form label-width="120px">
                            <el-form-item label="接收人" prop="SponsorUser">
                                <el-select width="100%" v-model="from.maintainUserPhone" multiple filterable
                                    placeholder="---请选择接收人---" style="width:100%">
                                    <el-option value="">接收人</el-option>
                                    <el-option v-for="(v, k) in AllUsers" :value="v.Phone" :data-userid="v.Phone"
                                        :label="v.UserName" v-text="v.UserName" />
                                </el-select>
                            </el-form-item>
                            <el-form-item label="合同提前预警" prop="SponsorUser">
                                <el-input type="text" v-model="from.maintain" placeholder="---合同提前天数预警天数---"></el-input>
                            </el-form-item>
                        </el-form>
                    </div>
                </el-card>
            </el-col>
        </el-row>

        <el-row :gutter="20">
            <el-col :span="8" :offset="2">
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>汽车年检</span>
                    </div>
                    <div>
                        <el-form label-width="120px">
                            <el-form-item label="接收人" prop="SponsorUser">
                                <el-select width="100%" multiple v-model="from.inspectionUserPhone" filterable
                                    placeholder="---请选择接收人---" style="width:100%">
                                    <el-option value="">接收人</el-option>
                                    <el-option v-for="(v, k) in AllUsers" :value="v.Phone" :data-userid="v.Phone"
                                        :label="v.UserName" v-text="v.UserName" />
                                </el-select>
                            </el-form-item>
                            <el-form-item label="年检提前预警" prop="SponsorUser">
                                <el-input type="text" v-model="from.inspection" placeholder="---年检提前天数预警天数---"></el-input>
                            </el-form-item>
                        </el-form>
                    </div>
                </el-card>
            </el-col>
            <el-col :span="8" :offset="2">
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>汽车保险</span>
                    </div>
                    <div>
                        <el-form label-width="120px">
                            <el-form-item label="接收人" prop="SponsorUser">
                                <el-select width="100%" v-model="from.insuranceUserPhone" multiple filterable
                                    placeholder="---请选择接收人---" style="width:100%">
                                    <el-option value="">接收人</el-option>
                                    <el-option v-for="(v, k) in AllUsers" :value="v.Phone" :data-userid="v.Phone"
                                        :label="v.UserName" v-text="v.UserName" />
                                </el-select>
                            </el-form-item>
                            <el-form-item label="保险提前预警" prop="SponsorUser">
                                <el-input type="text" v-model="from.insurance" placeholder="---保险提前天数预警天数---"></el-input>
                            </el-form-item>
                        </el-form>
                    </div>
                </el-card>
            </el-col>
            <el-col :span="8" :offset="2">
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>证书管理</span>
                    </div>
                    <div>
                        <el-form label-width="120px">
          
        <el-form-item label="到期提前预警" prop="SponsorUser">
            <el-input type="text" v-model="from.certificate" placeholder="---到期提前天数预警天数---"></el-input>
        </el-form-item>
        </el-form>
    </div>
    </el-card>
    </el-col>
    <el-col :span="8" :offset="2">
        <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span>网址账号管理</span>
            </div>
            <div>
                <el-form label-width="120px">
 
                    <el-form-item label="到期提前预警" prop="SponsorUser">
                        <el-input type="text" v-model="from.websiteAccount" placeholder="---到期提前天数预警天数---"></el-input>
                    </el-form-item>
                </el-form>
            </div>
        </el-card>
    </el-col>
    </el-row>




 
        <el-row :gutter="20">
            <el-col :span="8" :offset="2">
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>钉钉数据同步</span>
                    </div>
                    <el-button type="success" @click="DDSame()">数据同步</el-button>
                </el-card>
            </el-col>
            <el-col :span="8" :offset="2">
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>App文件更新</span>
                    </div>
                    <el-button type="success" @click="AppUpdata()">App版本更新</el-button>
                </el-card>
            </el-col>
        </el-row>   -->





 
        <el-row :gutter="20" style="margin-bottom: 20px;">
            <el-col :span="8" :offset="2">
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>项目负责人角色</span>
                    </div>
                    <el-select width="100%" v-model="RoleId" filterable placeholder="---请选择项目负责人权限---" style="width:100%">
                        <el-option v-for="(v, k) in roles" :value="v.Id + ''" :data-userid="v.Id + ''" :label="v.RoleName"
                            v-text="v.RoleName" />
                    </el-select>
                    <el-button type="success" style="width: 100%; margin-top: 20px;" @click="RoleSave()">数据同步</el-button>
                </el-card>
            </el-col>
			
			
			<el-col :span="8" :offset="2">
			    <el-card class="box-card">
			        <div slot="header" class="clearfix">
			            <span>员工角色</span>
			        </div>
			        <el-select width="100%" v-model="YG.RoleId" filterable placeholder="---请选择项員工角色---" style="width:100%">
			            <el-option v-for="(v, k) in roles" :value="v.Id + ''" :data-userid="v.Id + ''" :label="v.RoleName"
			                v-text="v.RoleName" />
			        </el-select>
			        <el-button type="success" style="width: 100%; margin-top: 20px;" @click="YuanGongSetUserId()">数据同步</el-button>
			    </el-card>
			</el-col>
        </el-row>

        <el-row :gutter="20">
            <el-col :span="8" :offset="2">
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>财务角色</span>
                    </div>
                    <el-select width="100%" v-model="CW.RoleId" filterable placeholder="---请选择财务权限---" style="width:100%">
                        <el-option v-for="(v, k) in roles" :value="v.Id + ''" :data-userid="v.Id + ''" :label="v.RoleName"
                            v-text="v.RoleName" />
                    </el-select>
                    <el-button type="success" style="width: 100%; margin-top: 20px;" @click="SetHeadUserIdHandler()">数据同步</el-button>
                </el-card>
            </el-col>
        </el-row>



        <!-- <el-row :gutter="20">
            <div style="text-align:center">
                <el-button type="success" round @click="SaveDb()">提交修改</el-button>
            </div>
        </el-row> -->

        <el-dialog :visible.sync="AppSetting_show" title="App版本更新" width="50%" @close="AppSettingClose">
            <AppSetting ref="AppSetting_ref" :biaoshi="biaoshi"></AppSetting>
        </el-dialog>
    </div>
</template>

<script>
import * as publicjs from "/public/Scriput/Public"
import AppSetting from "./AppSetting";
import WebsiteAccount from "../../Document/WebsiteAccount";

export default {
    name: 'SystemSetup',
    components: { AppSetting },
    data() {
        return {
            RoleId: 0,
            roles: [],
            AllUsers: [],
            quart: [],
            from: {
                maintainUserPhone: '',
                maintain: '',
                contractUserPhone: '',
                contract: '',
                inspectionUserPhone: '',
                inspection: '',
                insuranceUserPhone: '',
                insurance: '',
                certificate: '',
                certificateUserPhone: '',
                websiteAccount: '',
                websiteAccountUserPhone: '',
                roleId: ''
            },
            AppSetting_show: false,
            biaoshi: '',
            resData: {},
			YG:{
				RoleId: '',
			},
			CW:{
				RoleId: '',
			},
        }
    },

    created() {
        this.AllUsers = publicjs.GetCompanyAllUsers(this.$http);
    },
    methods: {
        GetAllRole() {
            let _this = this;
            console.log(1);
            this.$http.post("/Right/GetAllRole").then(res => {
                _this.roles = res.data.roles;

            })
            this.$http.post("/Right/GetHeadUserId").then(res => {
                _this.RoleId = res.data.roleid;

            })
        },
        GetSystemDb() {
            this.$http.post("/Right/GetSystemDb").then(res => {
                this.resData = {};
                for (let i = 0; i < res.data.data.length; i++) {
                    this.resData[res.data.data[i].FileName] = res.data.data[i];
                }
                this.from.maintainUserPhone = this.IntAttTostrarr(this.resData["Users"].phone);
                this.from.contractUserPhone = this.IntAttTostrarr(this.resData["CarmaintenanceCustom"].phone);
                this.from.inspectionUserPhone = this.IntAttTostrarr(this.resData["VehicleManagement"].phone);
                this.from.insuranceUserPhone = this.IntAttTostrarr(this.resData["VehicleManagementInsurance"].phone);
                this.from.certificateUserPhone = this.IntAttTostrarr(this.resData["CertificateManagement"].phone);
                this.from.websiteAccountUserPhone = this.IntAttTostrarr(this.resData["AccountManagement"].phone);

                this.from.maintain = this.resData["Users"].WarningDay;
                this.from.contract = this.resData["CarmaintenanceCustom"].WarningDay;
                this.from.inspection = this.resData["VehicleManagement"].WarningDay;
                this.from.insurance = this.resData["VehicleManagementInsurance"].WarningDay;
                this.from.certificate = this.resData["CertificateManagement"].WarningDay;
                this.from.websiteAccount = this.resData["AccountManagement"].WarningDay;
            });
        },

        SaveDb() {
            this.Getvaules();
            var url = "/Right/UpQuartZShortMessageModel";
            this.$http.post(url, { quart: this.quart }).then(res => {
                if (res.data.bol) {
                    this.$message.success("修改成功!");
                } else {
                    this.$message.error("修改失败,请重试!");
                }
                this.GetSystemDb();
            });
        },

        Getvaules() {
            this.quart = [];
            var quart = this.quart;
            //合同
            var demo2 = new Object();
            demo2.Id = this.resData["Users"] ? this.resData["Users"].Id : 0;
            demo2.MsgNumber = 459934;
            demo2.StartDate = "";
            demo2.EndDate = "";
            demo2.FileName = "Users"

            demo2.WarningDay = this.from.maintain
            demo2.Mileage = "";
            demo2.phone = this.from.maintainUserPhone == undefined ? '' : this.from.maintainUserPhone.join(',');
            ///年检
            var demo3 = new Object();
            demo3.Id = this.resData["VehicleManagement"] ? this.resData["VehicleManagement"].Id : 0;
            demo3.MsgNumber = 459922;
            demo3.StartDate = "";
            demo3.EndDate = "";
            demo3.FileName = "VehicleManagement"

            demo3.WarningDay = this.from.inspection;      //$(".VehicleManagementtxt").val();;
            demo3.Mileage = "";
            demo3.phone = this.from.inspectionUserPhone == undefined ? '' : this.from.inspectionUserPhone.join(',');

            //保险
            var demo4 = new Object();
            demo4.Id = this.resData["VehicleManagementInsurance"] ? this.resData["VehicleManagementInsurance"].Id : 0;
            demo4.MsgNumber = 542143;
            demo4.StartDate = "";
            demo4.EndDate = "";
            demo4.FileName = "VehicleManagementInsurance"

            demo4.WarningDay = this.from.insurance;       //$(".VehicleManagementInsurancetxt").val();;
            demo4.Mileage = ""
            demo4.phone = this.from.insuranceUserPhone == undefined ? '' : this.from.insuranceUserPhone.join(',');

            //保养
            var demo5 = new Object();
            demo5.Id = this.resData["CarmaintenanceCustom"] ? this.resData["CarmaintenanceCustom"].Id : 0;
            demo5.MsgNumber = 546465;
            demo5.StartDate = "";
            demo5.EndDate = "";
            demo5.FileName = "CarmaintenanceCustom"

            demo5.WarningDay = this.from.contract //$(".CarmaintenanceCustomtxt").val();;
            demo5.Mileage = ""
            demo5.phone = this.from.contractUserPhone == undefined ? '' : this.from.contractUserPhone.join(',');

            // 证书管理
            var demo6 = new Object();
            demo6.Id = this.resData["CertificateManagement"] ? this.resData["CertificateManagement"].Id : 0;
            demo6.MsgNumber = 1312824;
            demo6.StartDate = "";
            demo6.EndDate = "";
            demo6.FileName = "CertificateManagement"


            demo6.WarningDay = this.from.certificate //$(".CarmaintenanceCustomtxt").val();;
            demo6.Mileage = ""
            demo6.phone = !this.from.certificateUserPhone ? '' : this.from.certificateUserPhone.join(',');

            // 网址账号管理
            var demo7 = new Object();
            demo7.Id = this.resData["AccountManagement"] ? this.resData["AccountManagement"].Id : 0;
            demo7.MsgNumber = 1312824;
            demo7.StartDate = "";
            demo7.EndDate = "";
            demo7.FileName = "AccountManagement"

            demo7.WarningDay = this.from.websiteAccount //$(".CarmaintenanceCustomtxt").val();;
            demo7.Mileage = ""
            demo7.phone = !this.from.websiteAccountUserPhone ? '' : this.from.websiteAccountUserPhone.join(',');

            quart.push(demo2);
            quart.push(demo3);
            quart.push(demo4);
            quart.push(demo5);
            quart.push(demo6);
            quart.push(demo7);
        },

        DDSame() {
            this.$http.post('/Right/DingDingSame').then(res => {
                if (res.result) {
                    this.$message.success("数据同步成功!");
                } else {
                    this.$message.error("数据同步失败,请重试!");
                }
            });
        },
        RoleSave() {
            this.$http.post("/Right/SetHeadUserId", { id: this.RoleId }).then(res => {
                this.$message.success("负责角色修改成功");

            }).catch(error => {
                this.$message.error('服务器发生错误', error);
                console.error('服务器发生错误', error);
            });



        },
        //转化为数组
        IntAttTostrarr(objstr) {
            if (objstr != '') {
                var objarray = objstr.split(',');
                var Intarray = [];
                for (var i = 0; i < objarray.length; i++) {
                    Intarray.push((objarray[i]));
                }
                return Intarray;
            }
        },
        AppUpdata() {
            this.AppSetting_show = true
            this.$refs["AppSetting_ref"].Init()
        },
        //app设置关闭
        AppSettingClose() {
            this.$refs["AppSetting_ref"].FromReset()
        },
		//获取员工角色Id
		YuanGongGetUserId(){
			 this.$http.post("/Right/GetUserId").then(res => {
				this.YG.RoleId = res.data.Data.Userid;
			})
		},
		YuanGongSetUserId(){
			this.$http.post("/Right/SetUserId",{
				id:this.YG.RoleId
			}).then(res=>{
				const { StatusCode } = res.data || 0
				if(StatusCode == 200)this.$message.success("人员修改成功")
				else this.$message.error('服务器发生错误')
			})
		},
		GetFinancialIdHandler(){
			this.$http.post("/Right/GetFinancialId").then(res => {
				this.CW.RoleId = res.data.roleid;
			})
		},
		SetHeadUserIdHandler(){
			this.$http.post("/Right/SetFinancialId",{
				id:this.CW.RoleId
			}).then(res=>{
				const { StatusCode } = res.data || 0
				if(StatusCode == 200)this.$message.success("人员修改成功")
				else this.$message.error('服务器发生错误')
			})
		},
    },
    mounted: function () {
        this.GetSystemDb();
        this.GetAllRole();
		this.YuanGongGetUserId();
		this.GetFinancialIdHandler()
    },
};
</script>

<style>
.big_box {
    padding: 15px;
}

.el-row {
    margin-top: 20px;
}
</style>

